var uploaderCliente;
var uploaderNegociador;

dojo.require("dijit.ProgressBar");

function uploadLogo(isClient){
	
	var tipo = 0;
	var divToAppend;
	
	if(isClient){
		
		tipo = 1;
		uploaderCliente.setParams({
			"tipoLogo": tipo ,   	
		});
		dojo.attr(dojo.byId("imgCliente"),{
			
			"style":"display:none"
			
		});
		dojo.attr(dojo.byId("notAvailableBoxCliente"),{
			
			"style":"display:none"
			
		});
		divToAppend = dojo.byId("notAvailableBoxCliente");
		
	}else{
		uploaderNegociador.setParams({
			"tipoLogo": tipo ,   	
		});
		
		dojo.attr(dojo.byId("imgNegociador"),{
			
			"style":"display:none"
			
		});
		dojo.attr(dojo.byId("notAvailableBoxNegociador"),{
			
			"style":"display:none"
			
		});
		divToAppend = dojo.byId("notAvailableBoxNegociador");
		
	}
	
	
	
	var new_div = dojo.create("div");
	  dojo.attr(new_div,{
		  "id":"loading_row_"+tipo,
		  "style":"height:30px;"
	  });
	  
	  
	dojo.place(new_div,divToAppend,"before");
	
	if(dojo.isIE){
		
			dojo.attr(new_div,{
				
				"class":"loading"
			});		  

	}else{
		
		new dijit.ProgressBar({
		
			"class":"loading"
		},new_div);
		
	}
	

	
	
	
	
}

function createUploaders(){            
    uploaderNegociador = new qq.FileUploader({ 
        element: dojo.byId("divUploaderNegociador"),
        action: '/reuniao/interno/negociacao.cadastrarLogo',
        debug: false,
        template: '<div class="qq-uploader">' + 
        '<div class="qq-upload-drop-area"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div><span class="dijit dijitReset dijitInline dijitButton qq-upload-button"'+
        'widgetid="btnUploadFile"><span class="dijitReset dijitInline dijitButtonNode"'+
        'dojoattachevent="ondijitclick:_onButtonClick"><span class="dijitReset dijitStretch'+
        'dijitButtonContents" dojoattachpoint="titleNode,focusNode" role="button" aria-labelledby="btnUploadFile_label"'+
        'style="-webkit-user-select: none; " id="btnUploadFile" tabindex="0"><span class="dijitReset dijitInline dijitIcon"'+
        'dojoattachpoint="iconNode"></span><span class="dijitReset dijitToggleButtonIconChar"></span>'+
        '<span class="dijitReset dijitInline dijitButtonText" id="btnUploadFile_label" dojoattachpoint="containerNode">'+
    '$!{pageContext.idioma["negociacao.acoes.upload"]}</span></span></span><input name="btnUploadFile" type="button" value="" class="dijitOffScreen"'+
    'tabindex="-1" dojoattachpoint="valueNode"></span></div>',
        listElement : dojo.byId("nao_remover"),
        onSubmit: function(id, fileName){
        	
        	var tipo = false;
        	uploadLogo(tipo);
        },
        onProgress: function(id, fileName, loaded, total){
        	
        	if(!dojo.isIE){
        			
        		dijit.byId("loading_row_0").update({maximum: total, progress: loaded});
        	}
        },
        onComplete: function(id, fileName, responseJSON){
        	
        	
        	
        	dojo.attr(dojo.byId("imgNegociador"),{
        		
        		"src": "${pageContext.general.APP_PATH}imagens/logos/temp/"+responseJSON.nome, 
        		"style": "display:inline"	
        	});
        	
        	dojo.attr(dojo.byId("urlLogoNegociador"),{
        		
        		"value": responseJSON.nome
        		
        	});
        	dojo.attr(dojo.byId("notAvailableBoxNegociador"),{
        		
        		"style":"display:none"
        		
        	});
        	
        	if(!dojo.isIE){
        		dijit.byId("loading_row_0").destroy();
        	}else{
        		dojo.byId("divListaArtefatos").removeChild(dojo.byId("loading_row_0"));
        	}
        	 
        	
        },
    });
    
    uploaderCliente = new qq.FileUploader({ 
        element: dojo.byId("divUploaderCliente"),
        action: '/reuniao/interno/negociacao.cadastrarLogo',
        debug: false,
        template: '<div class="qq-uploader">' + 
        '<div class="qq-upload-drop-area"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div><span class="dijit dijitReset dijitInline dijitButton qq-upload-button"'+
        'widgetid="btnUploadFile2"><span class="dijitReset dijitInline dijitButtonNode"'+
        'dojoattachevent="ondijitclick:_onButtonClick"><span class="dijitReset dijitStretch'+
        'dijitButtonContents" dojoattachpoint="titleNode,focusNode" role="button" aria-labelledby="btnUploadFile2_label"'+
        'style="-webkit-user-select: none; " id="btnUploadFile2" tabindex="0"><span class="dijitReset dijitInline dijitIcon"'+
        'dojoattachpoint="iconNode"></span><span class="dijitReset dijitToggleButtonIconChar"></span>'+
        '<span class="dijitReset dijitInline dijitButtonText" id="btnUploadFile2_label" dojoattachpoint="containerNode">'+
    '$!{pageContext.idioma["negociacao.acoes.upload"]}</span></span></span><input name="btnUploadFile2" type="button" value="" class="dijitOffScreen"'+
    'tabindex="-1" dojoattachpoint="valueNode"></span></div>',
        listElement : dojo.byId("nao_remover"),
        onSubmit: function(id, fileName){
        	
        	var tipo = true;
        	uploadLogo(tipo);
        },
        onProgress: function(id, fileName, loaded, total){
        	
        	if(!dojo.isIE){
        			
        		dijit.byId("loading_row_1").update({maximum: total, progress: loaded});
        	}
        },
        onComplete: function(id, fileName, responseJSON){
                	
        	if(!dojo.isIE){
              		dijit.byId("loading_row_1").destroy();
        	}else{
        		dojo.byId("divListaArtefatos").removeChild(dojo.byId("loading_row_1"));
        	}

        	dojo.attr(dojo.byId("imgCliente"),{
        		
        		"src": "${pageContext.general.APP_PATH}imagens/logos/temp/"+responseJSON.nome, 
        		"style": "display:inline"	
        	});
        	dojo.attr(dojo.byId("urlLogoCliente"),{
        			
        		"value": responseJSON.nome
        		
        	});
        	
        	dojo.attr(dojo.byId("notAvailableBoxCliente"),{
        		
        		"style":"display:none"
        		
        	});
        			
        	
        },
    });
}